<!doctype html>
<html>
    <head>
        <meta charset="UTF-8"/>
        <title>添加城市</title>
	    <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
	    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
	    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
	    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
    </head>
    <body>
       <div class="easyui-container-fluid">
          <div class="easyui-panel" style="border:none;">
            <div class="nav" id="nav"></div> 
            <div class="easyui-panel" style="border:none;">
              <form id="ff" method="post">
                <div style="margin-bottom:20px">
                  <label class="item-label">代码：</label>
                  <input class="easyui-textbox" id="code" name="code" style="width:174px;" data-options="required:true" />
                </div>
                <div style="margin-bottom:20px">
                  <label  class="item-label">市/县：</label>
                  <input class="easyui-textbox" name="name" style="width:174px;" data-options="required:true" />
                </div>
                <div style="margin-bottom:20px">
                  <label  class="item-label">省份：</label>
                  <select class="easyui-combobox" name="provinceCode" id="province" style="width:174px">
                  </select>
                </div>
                <div style="margin-bottom:20px">
                  <label  class="item-label">市场级别：</label>
                  <select class="easyui-combobox" name="marketLevel" data-options="panelHeight:'auto'" style="width:174px">
                    <option value="">-请选择-</option>
                    <option value="ONE">一级市场</option>
                    <option value="TWO">二级市场</option>
                    <option value="THREE">三级市场</option>
                    <option value="FOUR">四级市场</option>
                  </select>
                </div>
                <div style="margin-bottom:20px">
                  <label  class="item-label">城市级别：</label>
                  <select class="easyui-combobox" name="cityLevel" data-options="panelHeight:'auto'" label="" style="width:174px">
                    <option value="">-请选择-</option>
                    <option value="ONE">一线城市</option>
                    <option value="TWO">二线城市</option>
                    <option value="THREE">三线城市</option>
                    <option value="FOUR">县域城市</option>
                  </select>
                </div>
                <div style="margin-bottom:20px">
                  <label  class="item-label">城市规模：</label>
                  <select class="easyui-combobox" name="cityScale" data-options="panelHeight:'auto'" label="" style="width:174px">
                    <option value="">-请选择-</option>
                    <option value="SUPER">超大城市</option>
                    <option value="HUGE">特大城市</option>
                    <option value="BIG">大城市</option>
                    <option value="MIDDLE">中城市</option>
                    <option value="SMALL">小城市</option>
                    <option value="TINY">县城</option>
                  </select>
                </div>
                <div style="margin-bottom:20px">
                  <label  class="item-label">南北方：</label>
                  <select class="easyui-combobox" name="north" data-options="panelHeight:'auto'" label="" style="width:174px">
                    <option value="">-请选择-</option>
                    <option value="false">南方</option>
                    <option value="true">北方</option>
                  </select>
                </div>
                <div style="margin-bottom:20px">
                  <label  class="item-label">城市区域：</label>
                  <select class="easyui-combobox" name="area" data-options="panelHeight:'auto'" label="" style="width:174px">
                    <option value="">-请选择-</option>
                    <option value="NORTH">华北地区</option>
                    <option value="SOURTH">华南地区</option>
                    <option value="EAST">华东地区</option>
                    <option value="MIDDLE">华中地区</option>
                    <option value="NORTH_EAST">东北地区</option>
                    <option value="NORTH_WEST">西北地区</option>
                    <option value="SOURTH_WEST">西南地区</option>
                  </select>
                </div>
                <div style="margin-bottom:20px;margin-left: 100px;">
                  <a href="javascript:void(0)" class="easyui-linkbutton c8" onclick="submitForm()" style="width:80px">保存</a>
                  <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()" style="width:80px">取消</a>
                </div>
              </form>
            </div>
          </div> 
       </div>  
    </body>
    <script type="text/javascript">
       var id=getQueryParameter("id");
       $(function(){
           setNav();
           if(id){
               $.when(initProvinceSelect('province')).done(function () {
                   $.ajax({
                       url:config.url +"/city",
                       type:'get',
                       data:{id:id},
                       xhrFields:{withCredentials:true},
                       success:function(data){
                           //填充表单
                           if(data){
                               $("#ff").form("load",changeProperty2String(data.content[0]));
                               $("#code").textbox("textbox").attr("readonly",true);
                           }
                       },
                       error:function(){

                       }
                   });
               });
          }else{
               initProvinceSelect('province');
           }
       });
       function submitForm(){
           $("#ff").form("submit",{
               onSubmit:function () {
                   var valid = $(this).form('enableValidation').form('validate');
                   if(valid){
                       var city = getFormData(document.getElementById("ff"));
                       var method = "POST";
                       if(id){
                           method = "PATCH";
                           city.id = id;
                       }
                       $.ajax({
                           url:config.url+"/city",
                           type:method,
                           data:JSON.stringify(city),
                           dataType:'json',
                           contentType:'application/json;charset=UTF-8',
                           xhrFields:{withCredentials:true},
                           beforeSend:function () {
                               $.messager.progress({
                                   title:"请稍等",
                                   interval:50,
                                   text:"操作进行中..."
                               });
                           },
                           complete:function () {
                               $.messager.progress("close");
                           },
                           success:function (data) {
                              if(data){
                                  $.messager.alert("提示","操作成功","info",function () {
                                      window.location.href="/webapp/pages/channel/city/list.html";
                                  });
                              }
                           },
                           error:function (XMLHttpRequest,textStatus,errorThrown) {
                               $.messager.progress("close");
                               $.messager.alert("提示","操作失败","error");
                           }
                       });
                       return false;
                   }
                   return false;
               }
           })
       }
       function clearForm(){
           window.location.href="/webapp/pages/channel/city/list.html";
       }
    </script>
</html>
